package org.lifxue.jqda.ui.util;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.SwingUtilities;

import org.lifxue.jqda.util.GlobalConstant;
import org.lifxue.jqda.util.GlobalVar;
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
import org.pushingpixels.substance.api.skin.SkinInfo;

/**
 * 
 * @Description:
 * @Author: zhangzuoqiang
 * @Date: Sep 26, 2011
 */
public class UIUtil {

	// private static Log logger = LogFactory.getLog(UIUtil.class);

	public static void setUI() {

		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {

				String lookandfeel = GlobalVar.CONFIG
						.get(GlobalConstant.CONFIG_LOOK_AND_FEEL);
				if (lookandfeel == null || lookandfeel.trim().equals("")) {
					// UIManager.setLookAndFeel(GlobalConstant.DEFAULT_LOOK_AND_FEEL);
					SubstanceLookAndFeel
							.setSkin(GlobalConstant.DEFAULT_LOOK_AND_FEEL);
				} else {
					Map<String, SkinInfo> hm = SubstanceLookAndFeel
							.getAllSkins();
					Iterator<Entry<String, SkinInfo>> skins = hm.entrySet()
							.iterator();
					while (skins.hasNext()) {
						Entry<String, SkinInfo> entry = (Entry<String, SkinInfo>) skins
								.next();
						SkinInfo skinInfo = (SkinInfo) entry.getValue();
						if (lookandfeel.equals(skinInfo.getClassName())) {
							SubstanceLookAndFeel.setSkin(lookandfeel);
							break;
						}
					}
				}

			}
		});
	}
}
